home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-serious-
/
programming
/
basic
/
mildred
/
mildred.lha
/
lha
/
BounceDemo.lha
/
Bounce.ascii
< prev
next >
Wrap
Text File
|
1999-03-03
|
3KB
|
144 lines
WBStartup
; Here is a demo of using MQSBlit to place queued cookie-cut objects behind
; a bitmap's stencil. Note that the unqueue does not take any notice of the stencil.
; You can substitute the MQSBlit with other things such as MQBlit, MQBlock, MQSBlock.
; Also if you take out the queue flush/unqueue line in the loop you can replace the
; MQSBlit with things like MBlit, MBlock, MTile32x32, MSBlit, etc.
; Change this filepath to wherever the supplied pic is:
Pic$="Work:Test2/5Ms.IFF"
#Width=320
#Height=192
#Objects=40
#UnQ=-1 ; Wether or not to unqueue the objects
;Init
MCPU Processor ; The two most important
Mc2pCPUmode Processor ; lines in your program!
MReserveShapes 5
MReserveBitmaps 2
MReservec2pWindows 1
MReserveQueues 1
Width.w=Max(#Width,320)
Mc2pWindow 0,Width,#Height
InitBank 0,Width*#Height,$10002
CludgeBitMap 0,Width,#Height,8,Bank(0)
InitPalette 0,256
Screen 0,0,0,Width,#Height,8,0,"Bounce",0,1,0
LoadIFF Pic$,0,0
ShowPalette 0
;Make a chunky shape
If MShape(0,64,64)=0 Then End
For y=0 To 63
For x=0 To 63
MPlotShape x,y,Point(x,y)
Next x
Next y
MMakeCookie 0
s=1
For y=0 To 32 Step 32
For x=0 To 32 Step 32
If MShape(s,32,32)=0 Then End
For yy=y To y+31
For xx=64+x To 64+x+31
MPlotShape xx MOD 32, yy MOD 32, Point(xx,yy)
Next xx
Next yy
MMakeCookie s
s+1
Next x
Next y
;Set up movement tables
Dim x.w(#Objects)
Dim y.w(#Objects)
Dim xdirection.b(#Objects)
Dim ydirection.b(#Objects)
Dim xdirectionswap.b(#Objects)
Dim ydirectionswap.b(#Objects)
For obj=1 To #Objects
x(obj)=Rnd(Width-40)+8
y(obj)=Rnd(#Height-40)+8
Repeat
xdirection(obj)=Rnd(8)-4
Until xdirection(obj)<>0
Repeat
ydirection(obj)=Rnd(8)-4
Until ydirection(obj)<>0
xdirectionswap(obj)=-xdirection(obj)
ydirectionswap(obj)=-ydirection(obj)
Next obj
;Prepare
If MBitmap(1,Width,#Height)=0 Then End
MAutoStencil On
If MBitmap(0,Width,#Height)=0 Then End
MUseShape 0
MClsStencil 0
For yy=0 To #Height-64 Step 64
For xx=0 To Width-64 Step 64
MSBlock xx,yy
Next xx
Next yy
MUseBitmap 1
MBlockScroll 0,0,Width,#Height,0,0,0
MUseBitmap 0
MQSBlitCut On
MSBlitCut On
MQueue 0,#Objects
;Loop
its=0
ResetTimer
While Joyb(0)=0 AND Joyb(1)=0
For obj=1 To #Objects
;Move
x(obj)+xdirection(obj)
If x(obj)<4 OR x(obj)>Width-36 Then Exchange xdirection(obj),xdirectionswap(obj)
y(obj)+ydirection(obj)
If y(obj)<4 OR y(obj)>#Height-36 Then Exchange ydirection(obj),ydirectionswap(obj)
;Try changing this to a different type of blit. If it's not a Q-type blit, comment-out the unqueue line also
MQSBlit (obj MOD 4)+1,x(obj),y(obj) ; Stencil-cut blit and add to queue
Next obj
;Display
Mc2p Bank(0) ; Display
;Comment this line out if not using a queued blit
If #UnQ Then MUnQueue 0,1 Else MFlushQueue 0
its+1
Wend
;Report
t=Timer
t=Max(t,1)
its=Max(its,1)
a.q=50.0/(t/its)
ScreenToBack_ Peek.l(Addr Screen(0))
FindScreen 1
Window 2,16,16,300,40,0,"Test results",1,0
WindowOutput 2
NPrint a," frames per second"
NPrint " "
NPrint "Press mouse/joy button..."
Repeat
Until Joyb(0)<>0 OR Joyb(1)<>0
End